﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="CustomerCheck.aspx.cs"
    Inherits="ZX.WebApp.Crm.Hodometer.CustomerCheck" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css">
        .style1
        {
             font-size:small;
        }
    </style>
    <link rel="stylesheet" href="style/StyleSheet1.css" />
    <script language="javascript" type="text/javascript">
        function $(id) { return document.getElementById(id) }
        function setvalue(obj) {
            //获取下一个控件的ID
            var next;
            var n = obj;
            do n = n.nextSibling;
            while (n && n.nodeType != 1);
            next = n.id;

            var hdfid = $(next);
            var CName = hdfid.id.replace("hdfcheckid", "lblCustomerName"); //原值控件
            var Dmaker = hdfid.id.replace("hdfcheckid", "lblDecisionmaker"); //原值控件
            var DPosition = hdfid.id.replace("hdfcheckid", "lblDecisionPosition"); //原值控件

            //产生列表
            var sInnerHtml = BuildHtml(hdfid.value, $(CName).innerHTML + "[" + $(Dmaker).innerHTML + "](" + $(DPosition).innerHTML + ")");
            $("divview").innerHTML = sInnerHtml;
        }
        function ChDate(strDate) {
            var reg =  /^([0-1]{1}\d|2[0-3]):([0-5]\d)$/;
            //var reg = /^\d{1}$|^1[0-9]$|^2[0-3]$/;
            //var reg = /^(\d{4})([-])(\d{1,2})([-])(\d{1,2})/;
            if (!reg.test(strDate)) {
                return false;
            }
            return true;
        }

        var Save = function (obj) {
            var hdid = $("hdchid");
            var hdname = $("taname");
            var cusid = "";
            if (hdid != null)
                cusid = hdid.value;

            if (queryString("CCID") == "" || hdid != null) {
                var addr = $("txtaddress").value;
                var dtime = $("txtdatetime").value;
                if (addr == "") {
                    alert("【地点】不能为空！");
                    $("txtaddress").focus();
                    return false;
                }
                if (dtime == "") {
                    alert("【时间】不能为空！");
                    return false;
                }
                else {
                    if (!ChDate(dtime.replace("：", ":"))) {
                        alert("时间格式错误；请输入对应的小时：分钟");
                        return false;
                    }
                }
            }
            var back = ZX.WebApp.Crm.Hodometer.CustomerCheck.SaveCus(queryString("CCID") + "︾" + queryString("TEAID") + "︾" + queryString("DATED") + "︾" + queryString("TA") + "︾" + cusid + "︾" + addr + "︾" + dtime).value;
            if (contains(back, "成功", false)) {
                var hdcid = "";
                if (contains(back, "新增", false)) {
                    var strs = back.split('|');
                    hdcid = strs[0];
                    alert(strs[1]);
                }
                else {
                    alert(back);
                }
                var ta = parent.$(queryString("TA"));
                var hd = parent.$(queryString("HD"));
                if (hdname != null) {
                    ta.value = hdname.value + "{" + $("txtaddress").value + "}" + "{" + $("txtdatetime").value + "}--" + $("hdfusername").value;
                    setParentValue(ta);
                }
                else {
                    ta.value = "";
                    hd.value = "";
                }
                if (hdcid != "") {
                    hd.value = hdcid;
                }

                return true;
            }
            else {
                alert(back);
                return false;
            }
        }
        function setParentValue(ta) {
            if (ta != null && ta.value != "") {
                var hdcid = $("hdchid");
                var val = ta.value.split('[');
                var oLink = document.createElement("a");
                oLink.id = hdcid.value;
                oLink.onclick = (function pop() { hrefModify(hdcid.value); });
                oLink.innerHTML = "<font color=blue>" + val[0] + "</font>";
                ta.value = "";
                var oL = document.createElement("a");
                oL.innerHTML = "[" + val[1];
                ta.appendChild(oLink);
                ta.appendChild(oL);
            }
        }
        //链接跳到查看客户信息
        function hrefModify(id) {
            parent.parent.$("#tabs").tabs('close', '查看客户信息');
            parent.parent.addTabs('查看客户信息', '../Crm/Customer/AddCustomer.aspx?entity=CrmCustomer&id=' + id);

        }
        function ReviewSelected(obj) {
            if (obj !=null&&obj!=''&&obj!= "") {
                var strs = obj.split('|')
                var sInnerHtml = BuildHtml(strs[0],strs[1]);
                $("divview").innerHTML = sInnerHtml;
                $("txtaddress").value = strs[2];
                $("txtdatetime").value = strs[3];
            }
        }

        //检查是否已经选择此记录
        function CheckSelected(obj, Textvalue) {
            var str = obj.split(';');
            for (var i = 0; i < str.length; i++) {
                if (str[i] == Textvalue) {
                    return false;
                    break;
                }
            }
            return true;
        }
        //清空动作，清空DIV及VALUE，并且使页面所有checkbox为非选中状态
        function ClearClick(gvName) {
            parent.$get("hdfcodeValue").value = '';
            parent.$get("ShowSelected").innerHTML = '';
            var chkbox = $get(gvName).getElementsByTagName("INPUT");
            for (var x = 0; x < chkbox.length; x++) {
                if (chkbox[x].type == 'checkbox' && chkbox[x].checked) {
                    chkbox[x].checked = false;
                }
            }
            return false;
        }

        //产生列表方法
        function BuildHtml(id, name) {
            var sInnerHtml = '<TABLE class="cmf_tb"  style="float:left;" id="' + id + '">' +
    '<TR><TD class="btnChooseImage"><input id="hdchid" type="hidden" value="' + id + '" /><input id="taname" type="hidden" value="' + name + '" /></TD><TD><NOBR><a id=' + "hrefClick" + '  >' +
    '' + name + '</a></NOBR></TD><TD><A   title="删除讲师行程" style="TEXT-DECORATION:none;color:red;"  href=' + "#" + ' onclick="return RemoveChild(\'' + id + '\');" InputID="' + id + '" ' +
    '> <img title="删除讲师行程"  style=" border:0px;" src="style/cancel.gif" /></A></TD><TD>;</TD></TR></TABLE>';
            return sInnerHtml;
        }

        //根据checkbox选中与否状态去删除记录显示DIV及记录Value
        function RemoveChild(obj) {
            var listfile = $("divview");
            if ($(obj) == null) return false;
            listfile.removeChild($(obj));
        }
        //判断记录是否已经有选择
        function CheckIsChoose(id) {
            var hdfcodeValue = $get("hdfcode").value;
            var str = hdfcodeValue.split(';');
            for (var i = 0; i < str.length; i++) {
                if (str[i] == id) {
                    return true;
                    break;
                }
            }
            return false;
        }
        //提示信息
        function malert(obj) {
            alert(obj);
        }

        function SetValue(oid, oname) {
            var ids = oid.split(';');
            var nms = oname.split(';');
            for (var i = 0; i < ids.length - 1; i++) {
                //产生列表
                var sInnerHtml = BuildHtml(ids[i], nms[i]);
                $get("divview").innerHTML += sInnerHtml;
            }
        }

        function RefreshData() {
            if (parent.NeedRefreshPage != null) {
                if (typeof (parent.NeedRefreshPage.LoadData) == "function") {
                    parent.NeedRefreshPage.RefreshData();
                }
            }
        }
        //只取一个URL参数：
        var queryString = function (key) {
            return (document.location.search.match(new RegExp("(?:^\\?|&)" + key + "=(.*?)(?=&|$)")) || ['', null])[1];
        }
        // string:原始字符串
        //substr:子字符串
        //isIgnoreCase:忽略大小写
        function contains(string, substr, isIgnoreCase) {
            if (isIgnoreCase) {
                string = string.toLowerCase();
                substr = substr.toLowerCase();
            }
            var startChar = substr.substring(0, 1);
            var strLen = substr.length;
            for (var j = 0; j < string.length - strLen + 1; j++) {
                if (string.charAt(j) == startChar)  //如果匹配起始字符,开始查找
                {
                    if (string.substring(j, j + strLen) == substr)  //如果从j开始的字符与str匹配，那ok
                    {
                        return true;
                    }
                }
            }
            return false;
        }
        //替换所有
        //s1原始字符串
        //s2子字符串
        //s3子字符串要替换成的值
        function replaceAll(s1, s2, s3) {
            var r = new RegExp(s2.replace(/([\(\)\[\]\{\}\^\$\+\-\*\?\.\"\'\|\/\\])/g, "\\$1"), "ig");
            return s1.replace(r, s3);
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table >
            <tr>
                <th>
                    <asp:Label ID="lblKcid" runat="server" Text='客户名称：' ></asp:Label>
                </th>
                <td>
                    <asp:TextBox ID="txtkhname" runat="server"  MaxLength="40"></asp:TextBox>
                </td>
                <td>
                    <asp:Button ID="BtnQuery" runat="server" Text="查询"   OnClick="BtnQuery_Click" />
                </td>
                <td></td>
            </tr>
        </table>
            <div style=" width:100%; height:260px; OVERFLOW-y:auto;">
            <asp:GridView ID="gvDataView" runat="server" Width="95%"  AllowPaging="false"
                AutoGenerateColumns="False" DataKeyNames="ID"  
                OnRowDataBound="gvDataView_RowDataBound"  ForeColor="#333333" 
                GridLines="Both">
                <AlternatingRowStyle BackColor="White" />
                <Columns>
                    <asp:TemplateField>
                        <ItemStyle Width="20px" />
                        <ItemTemplate>
                            <input  id="chks" type="radio" name="radio" onclick="setvalue(this)"  />
                            <asp:HiddenField ID="hdfcheckid" Value='<%# Eval("ID") %>' runat="server" />
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:BoundField DataField="Code" HeaderText="客户编码" />
                    <asp:TemplateField HeaderText="客户名称">
                        <ItemTemplate>
                            <asp:Label ID="lblCustomerName" runat="server" Text='<%# Eval("CustomerName") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="决策人">
                        <ItemTemplate>
                            <asp:Label ID="lblDecisionmaker" runat="server" Text='<%# Eval("Decisionmaker") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="决策人职位">
                        <ItemTemplate>
                            <asp:Label ID="lblDecisionPosition" runat="server" Text='<%# Eval("DecisionPosition") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <EditRowStyle BackColor="#2461BF" />
                <EmptyDataTemplate>
                    没有任何信息可以显示。
                </EmptyDataTemplate>
                <FooterStyle BackColor="#307CD1" ForeColor="White" />
                <HeaderStyle BackColor="#307CD1" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#EFF3FB" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#F5F7FB" />
                <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                <SortedDescendingCellStyle BackColor="#E9EBEF" />
                <SortedDescendingHeaderStyle BackColor="#4870BE" />
            </asp:GridView>
        </div>
        <fieldset style=" width:91%;" >
            <legend>已选客户</legend>
            <asp:HiddenField ID="hdfselectid" runat="server" />
            <asp:HiddenField ID="hdfusername" runat="server" />
            <div id="divview" style=" width:90%; float:left;">
            </div>
            <table class="style1">
            <tr>
            <td>地点</td>
            <td><asp:TextBox ID="txtaddress" runat="server"  MaxLength="40"></asp:TextBox></td>
            <td>时间</td>
            <td><asp:TextBox ID="txtdatetime" runat="server" Width="50px"  MaxLength="40"></asp:TextBox>(格式：HH:MM)</td>
            </tr>
            </table>
        </fieldset>
    </div>
    </form>
</body>
</html>
